function openScanerSettings(){
	var scaner = ScanOcx;
//	Microtek_6240S.open();
	
	var cookieMD = getFromCookie("MediDocumenter")
	if(cookieMD=='Microtek_S8090' || cookieMD=='Microtek_S8090_RGB'){
		scaner.DSMode(8);//
	}else if(cookieMD=='Microtek_6240S_NEW'){
		scaner.DSMode(9);// SW_BIO
	}else{
		scaner.DSMode(0);//
	}	
	scaner.openScanner();
    
	if(scaner.GetCapShowUISettings()==0){
		alert("此款扫描仪不支持打开本地界面，请从扫描仪设置！");
	}
	scaner.ShowUISettings();
}

//判断是否为空
function isUseful(str){
	if (str == null || str.length == 0 || "null" == str || "undefined" == str){
		return false;
	}
	return true;
}


function isUse(str){
	return isUseful(str);
}

function isNull(s){
	if (s == null || s.length == 0 || "null" == s || "undefined" == s){
		return true;
	}
	return false;
}

function getNotNullString($s){
	if (isNull($s)){
		return "";
	}
	return $s;
}

function getNotNullString($s,$q5k7p1d6){
	if ($q5k7p1d6 == null){$q5k7p1d6 = "";}
	if (isNull($s)){
		return $q5k7p1d6;
	}
	return $s;
}


//时间格式
function parseDate(date, type){
	var returnValue = "";
	if ($.type(date) === "date"){
		if (type == "chinese"){
			returnValue += date.getFullYear()+"年";
			returnValue += (date.getMonth()+1)+"月";
			returnValue += (date.getDate())+"日";
			returnValue += ""+(date.getHours())+"时";
			returnValue += +(date.getMinutes())+"分";
			returnValue += +(date.getSeconds())+"秒";
		}
		else if (type == "simple"){
			returnValue += date.getFullYear()+"-";
			returnValue += parseInt(date.getMonth()+1)<10?"0"+(date.getMonth()+1)+"-":date.getMonth()+1+"-";
			returnValue += parseInt(date.getDate())<10?"0"+(date.getDate()):(date.getDate());
		}else{
			returnValue += date.getFullYear()+"-";
			returnValue += $h3u5s5t7t2n4p4k9t5(""+(date.getMonth()+1),2)+"-";
			returnValue += $h3u5s5t7t2n4p4k9t5(""+date.getDate(),2);
			returnValue += " "+$h3u5s5t7t2n4p4k9t5(""+date.getHours(),2);
			returnValue += ":"+$h3u5s5t7t2n4p4k9t5(""+date.getMinutes(),2);
			returnValue += ":"+$h3u5s5t7t2n4p4k9t5(""+date.getSeconds(),2);
		}//
	}else if ($.type(type) === "string"){
		if (!isNull(date)){
			returnValue = date.substring(0,date.indexOf("."));////
		}
	}
	
	return returnValue;
}

function $h3u5s5t7t2n4p4k9t5($u5j1k9f9u5,$h3z3t2n4p4k9t5){
	var $p8j5k3d6k9g0u5g5 = $h3z3t2n4p4k9t5-$u5j1k9f9u5.length;
	var $x1f9t2o5h3q4 = "";
	for (var $i = 0;$i < $p8j5k3d6k9g0u5g5;$i++){
		$x1f9t2o5h3q4 += "0";
	}
	return $x1f9t2o5h3q4+$u5j1k9f9u5;
}

function fun3(){
	if ("49557184-0" == Scan.OrgCode){//temp
		if ("230822198709197826" == Scan.CardId){
			return true;
		}else{
			return false;
		}
	}
	return true;
}

function getDocPageSpan_up(lianSao){
	getDocPageImgHeight();//注释： 设置图像的大小
	var arrayList = Scan.MrDocViewOrBoardList;
	if(arrayList.length == 0 || (arrayList.length > 0 && Scan.ItemOneDocID != Scan.CurrentMrId) || lianSao == 1){
		dwr.engine.setAsync(false);
		ScanBiz.getSaoMiaoByIdentity(Scan.OrgCode, Scan.CurrentMrId, {
			callback:function(data){
				arrayList = data;
				Scan.MrDocViewOrBoardList = arrayList;
			},
			warningHandler:function(message){return; },
			errorHandler:function(message){return; }
		})
	}
	var len = arrayList.length;
	$("#CurrentTotalPagecount").text(""+len);
	var $s = "";
	for (var i = 0;i < len;i++){
		var saoMiao = arrayList[i];
		$s += getDocPageSpan(saoMiao,i);
	}
	
	if (null != $s){
		$("#MrDocViewOrBoard").html($s);
	}
	
	$("img[__p1i3k9z8a7j5t7c6='docPageImg']").lazyload({
		container: $("#MrDocViewOrBoard")
	});
	
	$("[__q1t7k3u5u5='docPageImg']",$q3s5k3f9q5).on(
			{
				"click":function(){// 注释:点击图片
					activeDocPageImg(this);
					return false;
				},
				"dblclick":function(){
					if (Scan.Mode != "fullWidth"){
						Scan.Mode = "fullWidth";
						getDocPageSpan_up();
					}else{
						Scan.Mode = "fullHeight";
						getDocPageSpan_up();
					}
					return false;
				}
			}
		);
		
	activeDocPageImg();
}

function getDocPageSpan(saoMiao,i){
	if (null == i){
		i = getj6n4q5t2q4(saoMiao.id);
	}
	
	var $s = "";
	var mode = Scan.Mode;
	if ("thumbnail" == mode){
		$s += "<span class=\"docPage\" style=\"display:inline-block;\"" +
					" __q1t7k3u5u5=\"docPage\"" +
					" __x1k3p4t2j6q5=\""+getNotNullString(saoMiao.id)+"\">"+
				"<span class=\"imgBox\">"+// modify div to span at 2015-12-02
					getImgBoxDiv(saoMiao)+
				"</span>"+
			
				"<div class=\"docPageTexts\">"+
					"<span class=\"docPageNumber\" __q1t7k3u5u5=\"docPageNumber\">No."+(i+1)+"</span>"+
					//"<span class=\"docPageCode\" __q1t7k3u5u5=\"docPageCode\">"+saoMiao.jlh+"</span>"+
					"<br/>"+
					"<span class=\"docPageType\" __q1t7k3u5u5=\"docPageType\">"+
						getMrPageTypeName(saoMiao.pagename)+"</span>"+
				"</div>"+
			"</span>";
	}else if ("fullHeight" == mode){// 注释：全屏下循环显示图片
		$s += "<div class=\"docPage\"" +
		" __q1t7k3u5u5=\"docPage\"" +
		" __x1k3p4t2j6q5=\""+getNotNullString(saoMiao.id)+"\">"+
		"<div><span class=\"imgBox\">"+
			getImgBoxDiv(saoMiao)+
			"</span>"+
		"</div>"+
		
		"<div class=\"docPageTexts\">"+
			"<span class=\"docPageNumber\" __q1t7k3u5u5=\"docPageNumber\">No."+(i+1)+"</span>" +
			"&nbsp;&nbsp;";
		
		if ("work" == Scan.WorkType){
			$s += "<span class=\"docPageCode\" __q1t7k3u5u5=\"docPageCode\">记录号: "+saoMiao.jlh+"</span>"+
			"&nbsp;&nbsp;";
			saoMiao.id+
			"&nbsp;&nbsp;";
		}
			
		$s += "<span class=\"docPageType\" __q1t7k3u5u5=\"docPageType\">页面属性: "+
				getMrPageTypeName(saoMiao.pagename)+"</span>";
		
		if ("work" == Scan.WorkType){
			$s += "&nbsp;&nbsp;"+
				""+
				"<span class=\"docPageUSER-SCAN\">扫描者: "+
					getNotNullString(saoMiao.userScanName)+"</span>"+
					"&nbsp;&nbsp;<font color='#ADADAD'>编页者:</font> "+
				"<span class=\"docPageUSER-CATALOGUE\">"+
					getNotNullString(saoMiao.userCatalogueName)+"</span>";
		}
		
		$s += "</div>"+
		"</div>";//alert($s);
	}else{//fullWidth or others
		$s += "<div class=\"docPage\"" +
				" __q1t7k3u5u5=\"docPage\"" +
				" __x1k3p4t2j6q5=\""+getNotNullString(saoMiao.id)+"\">"+
			"<div><span class=\"imgBox\">"+
				getImgBoxDiv(saoMiao)+
			"</span></div>"+
			
			"<div class=\"docPageTexts\">"+
				"<span class=\"docPageNumber\" __q1t7k3u5u5=\"docPageNumber\">No."+(i+1)+"</span>" +
				"&nbsp;&nbsp;";
			
			if ("work" == Scan.WorkType){
				$s += "<span class=\"docPageCode\" __q1t7k3u5u5=\"docPageCode\">记录号: "+saoMiao.jlh+"</span>"+
				"&nbsp;&nbsp;";
				saoMiao.id+
				"&nbsp;&nbsp;";
			}
			
			$s += "<span class=\"docPageType\" __q1t7k3u5u5=\"docPageType\" title=\""+saoMiao.filename+"\">页面属性: "+
					getMrPageTypeName(saoMiao.pagename)+"</span>";
			
			if ("work" == Scan.WorkType){
				$s += "&nbsp;&nbsp;"+
					""+
				"<span class=\"docPageUSER-SCAN\">扫描者: "+
					getNotNullString(saoMiao.userScanName)+"</span>"+
					"&nbsp;&nbsp;<font color='#ADADAD'>编页者:</font> "+
				"<span class=\"docPageUSER-CATALOGUE\">"+
					getNotNullString(saoMiao.userCatalogueName)+"</span>";
			}
			
			$s += "</div>"+
		"</div>";
	}
	return $s;
}

function getImgBoxDiv(saoMiao){
	var $s = "<img class=\"docPageImg\" __q1t7k3u5u5=\"docPageImg\" " +
		" __x1k3p4t2j6q5=\""+getNotNullString(saoMiao.id)+"\"" +
		" style=\"height:"+Scan.imgHeight+
		";width:"+Scan.imgWidth+"\"";
	
	var fileUrl = saoMiao.fileUrl;//注释：data-origina路径
	//if ("work" == Scan.WorkType){
		//fileUrl += "?t="+new Date().getTime();
	//}
	//alert(fileUrl);
	var $mode = Scan.Mode;
	if ($mode.indexOf(",") > 0 || "fullWidth" == $mode){
		if (Scan.WorkType == "view"){
			$s += " src=\""+fileUrl+"\"";
		}else{
			$s += " src=\""+Scan.getTranSparentPng+"\""+
				" __p1i3k9z8a7j5t7c6=\"docPageImg\""+
				" data-original=\""+fileUrl+"\"";
		}
	}else if ("fullHeight" == $mode){
		if (Scan.WorkType == "view"){
			$s += " src=\""+fileUrl+"\"";
		}else{
			if ("work" == Scan.WorkType){
				fileUrl = fileUrl.replace("thumbnail_","thumbnail");
				fileUrl = fileUrl.replace("source","thumbnail");
			}
			
			$s += " src=\""+Scan.getTranSparentPng+"\""+
				" __p1i3k9z8a7j5t7c6=\"docPageImg\""+
				" data-original=\""+fileUrl+"\"";
		}
	}else if ("thumbnail" == $mode){
		fileUrl = fileUrl.replace("thumbnail_","thumbnail");
		fileUrl = fileUrl.replace("source","thumbnail");
		
		$s += " src=\""+Scan.getTranSparentPng+"\""+
		" __p1i3k9z8a7j5t7c6=\"docPageImg\""+
		" data-original=\""+fileUrl+"\"";
	}
	
	$s += "/>";
	return $s;
}

function getMrPageTypeName(pageCode){
	var stdMrPageTypeList = Scan.MrPageTypeList;
	if(stdMrPageTypeList.length == 0){
		dwr.engine.setAsync(false);
		ScanBiz.getMarPageType({
			callback:function(data){
				stdMrPageTypeList = data;
				Scan.MrPageTypeList = stdMrPageTypeList;
			},
			warningHandler:function(message){return; },
			errorHandler:function(message){return; }
		})
	}
	var len = stdMrPageTypeList.length;
	for (var i = 0;i < len;i++){
		if (pageCode == stdMrPageTypeList[i].code){
			if (pageCode == "99"){
				return stdMrPageTypeList[i].code+"-未归类";
			}
			return stdMrPageTypeList[i].code+"-"+stdMrPageTypeList[i].name;
		}
	}
	return "";
}

function getDocPageImgHeight(){
	this.j$q3s5k3f9q5 = $("#MrDocViewOrBoard");
	this.$q3s5k3f9q5 = this.j$q3s5k3f9q5[0];
	
	var $mode = Scan.Mode;
	if ("thumbnail" == $mode){
		var $w = j$q3s5k3f9q5.width()-($(j$q3s5k3f9q5[0].parentNode).outerWidth(true)-j$q3s5k3f9q5.width());
		Scan.imgWidth = parseFloat($w/3-30)+"px";
		Scan.imgHeight = "";
	}
	else if ("fullHeight" == $mode){
		Scan.imgWidth = "";
		Scan.imgHeight = (j$q3s5k3f9q5.height()-40)+"px";
	}
	else if ("fullWidth" == $mode){
		Scan.imgWidth = (j$q3s5k3f9q5.width()-(j$q3s5k3f9q5.outerWidth(true)-j$q3s5k3f9q5.width())-6)+"px";
		Scan.imgHeight = "";
	}else if ($mode.indexOf(",") > 0){
		var $k9z8p1d6p1d6 = $mode.split(",");
		Scan.imgWidth = parseFloat($k9z8p1d6p1d6[0])+"px";
		Scan.imgHeight = parseFloat($k9z8p1d6p1d6[1])+"px";
	}
}

function activeDocPageImg(docPageImg){
	if(docPageImg == null){
		var mrDocView = Scan.MrDocViewOrBoardList;
		if (mrDocView.length > 0 && (Scan.ArmID == "" || Scan.CurrentMrId != Scan.ItemOneDocID)){// 注释：add && Scan.ArmID == "" at 2015-12-17
			docPageImg = mrDocView[0];
			Scan.ArmID = docPageImg.id;
		}
	}else if(typeof docPageImg === "string"){//注释：传的实体是docPageImg，即saoMiao实体
		Scan.ArmID = docPageImg;
	}else{
		if (null != docPageImg.getAttribute("__x1k3p4t2j6q5")){
			Scan.ArmID = docPageImg.getAttribute("__x1k3p4t2j6q5");
		}else if(null != docPageImg.getAttribute("__a7k3t7I1t2")){//注释：传的实体不是docPageImg，是itemOnePageType
			if (isUse(Scan.PageTypeCode)){
				var $x1k3p4t2q6p1x1t2s5 = getb7k3p4t2q6p1x1t2(Scan.PageTypeCode);
				Scan.ArmID = $x1k3p4t2q6p1x1t2s5.$x1k3p4t2w0[0];
			}
		}
	}
	getCurrentDocPageImg(Scan.ArmID);// 注释：获得点击当前div的实体封装
	var j$k3q1k9h3a7t2b7k3p4t2j6p8p4m7s5q5t2 = $($k3q1k9h3a7t2b7k3p4t2j6p8p4m7s5q5t2());
	if (j$k3q1k9h3a7t2b7k3p4t2j6p8p4m7s5q5t2.length > 0){
		var j$q3s5k3f9q5 = $("#MrDocViewOrBoard");
		var $q3s5k3f9q5 = j$q3s5k3f9q5[0];
	
		var $h = j$k3q1k9h3a7t2b7k3p4t2j6p8p4m7s5q5t2.position().top
			- j$q3s5k3f9q5.position().top
			- (parseInt((j$q3s5k3f9q5.outerHeight(true)-j$q3s5k3f9q5.height())/2));
		
		//alert($h);
		j$q3s5k3f9q5.scrollTop(j$q3s5k3f9q5.scrollTop()+$h );
		
		setActiveCSS(j$k3q1k9h3a7t2b7k3p4t2j6p8p4m7s5q5t2[0],$q3s5k3f9q5);
	}
	
	var $u5g5k9g0k9g0I1v2 = true;
	var pageName = "99";
	if(Scan.CurrentDocPageImg != null){
		pageName = Scan.CurrentDocPageImg.pagename;//注释：获取当前点击的pageName，待优化
	}
	
	
	$("[__q1t7k3u5u5='itemOnePageType']").each(
		function(){
			if (this.getAttribute("__a7k3t7I1t2") == pageName){
				
				Scan.PageTypeCode = this.getAttribute("__a7k3t7I1t2");
				var $e3k6q6i0o8b7r8f7s5t7t7s5f9s5m5p4j5h7i3 = $("#PageTypeSelector");
				
				if ("99" != pageName){
					$u5q1f9s5t7t7q6s5x1($(this),$e3k6q6i0o8b7r8f7s5t7t7s5f9s5m5p4j5h7i3);
				}
				
				setActiveCSS(this,$e3k6q6i0o8b7r8f7s5t7t7s5f9s5m5p4j5h7i3[0]);
				
				if ($("#MrDocPrinttypes")[0] != null){
					
				}else if ($("#CatalogerWorkMenuOrB")[0] != null){
					
				}else{
					Scan.PageTypeCode = pageName;
					$k9f9t2t2h3n4p4x0p1b7k3p4t2k9p1x1t2(this);//注释：选中右侧列表
					$u5g5k9g0k9g0I1v2 = false;
				}
			}
		}
	);
	
	if ($u5g5k9g0k9g0I1v2){
		$("[__q1t7k3u5u5='itemOneDocPage']",$("#ItemCurrentDocPages")[0]).each(
			function(){
				if (this.getAttribute("__x1k3p4t2j6q5") == Scan.ArmID){
					var $e3k6q6i0o8b7r8f7s5t7t7s5f9s5m5p4j5h7i3 = $("#ItemCurrentDocPages");
					$u5q1f9s5t7t7q6s5x1($(this),$e3k6q6i0o8b7r8f7s5t7t7s5f9s5m5p4j5h7i3);
					setActiveCSS(this,$e3k6q6i0o8b7r8f7s5t7t7s5f9s5m5p4j5h7i3[0]);
				}
			}
		);
	}
};
/**
 * 获取当前docPage
 * @returns
 */
function $k3q1k9h3a7t2b7k3p4t2m7s5q5t2(){
	return $(
		"[__q1t7k3u5u5='docPage'][__x1k3p4t2j6q5='"+Scan.ArmID+"']",
		this.$q3s5k3f9q5)[0];
};

function $k3q1k9h3a7t2b7k3p4t2j6p8p4m7s5q5t2($u5g5p4j5I1v2k9g0){
	if (null == $u5g5p4j5I1v2k9g0){
		$u5g5p4j5I1v2k9g0 = this.$k3q1k9h3a7t2b7k3p4t2m7s5q5t2();
	}
	
	if (null == $u5g5p4j5I1v2k9g0){
		return null;
	}else{
		return $("[__q1t7k3u5u5='docPageImg']",$u5g5p4j5I1v2k9g0)[0];
	}
};

function $u5q1f9s5t7t7q6s5x1(jscanerSettingBtn,j$w0z8p4j5h7i3){
	var $d1c6j6d6 = jscanerSettingBtn.position().top;
    var $d1c6p4v2 = j$w0z8p4j5h7i3.position().top;
    var $h = $d1c6j6d6 - $d1c6p4v2
		- (parseInt((j$w0z8p4j5h7i3.outerHeight(true)-j$w0z8p4j5h7i3.height())/2));
					
	if ($h < 0 || ($h > (j$w0z8p4j5h7i3.height()-jscanerSettingBtn.outerHeight(true)))){
		j$w0z8p4j5h7i3.scrollTop( j$w0z8p4j5h7i3.scrollTop()+$h);
	}
}

function setActiveCSS(scanerSettingBtn,$s5p5n4q1t2u5k9s5f9){
	if (null == scanerSettingBtn){
		return;
	}
	
	var cssClassName = scanerSettingBtn.className;
	if (isNull(cssClassName)){
		return;
	}
	
	if (null == $s5p5n4q1t2u5k9s5f9){
		$s5p5n4q1t2u5k9s5f9 = document.body;
	}
	
	var $q1t7k3u5u5m7k3p8t2 = "";
	var $q1t7k3u5u5m7k3p8t2a1n4 = "";
	
	if (cssClassName.substring(cssClassName.length-2) == "On"){
		$q1t7k3u5u5m7k3p8t2 = cssClassName.substring(0,cssClassName.length-2);
		$q1t7k3u5u5m7k3p8t2a1n4 = cssClassName;
	}else{
		$q1t7k3u5u5m7k3p8t2 = cssClassName;
		$q1t7k3u5u5m7k3p8t2a1n4 = cssClassName+"On";
	}
	
	$("."+$q1t7k3u5u5m7k3p8t2a1n4,$s5p5n4q1t2u5k9s5f9).each(
		function(){
			this.className = $q1t7k3u5u5m7k3p8t2;
		}
	);
	
	scanerSettingBtn.className = $q1t7k3u5u5m7k3p8t2a1n4;
}

function getCurrentAimID(){
	// 未指定时取第一个
	if(Scan.ArmID == ""){
		var mrDocView = Scan.MrDocViewOrBoardList;
		if (mrDocView.length > 0){
			Scan.ArmID = mrDocView[0].id;
			return Scan.ArmID;
		}else{
			return "";
		}
	}
};

function getCurrentDocPageImg(aimId){
	for(var i=0; i<Scan.MrDocViewOrBoardList.length;i++){
		if(Scan.MrDocViewOrBoardList[i].id == aimId){
			Scan.CurrentDocPageImg = Scan.MrDocViewOrBoardList[i];
			return;
		}
	}
}

var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
var adoStream;

function startScan(bSuccess){
	///*
	if (bSuccess == 1){
		this.update();
	}else{
		//ScanOcx.CancelXfers();
		//alert("错误代码："+ScanOcx.GetErrorCode()+"\r\n此页文件扫描未成功，请重新扫描！");
	}
	//*/
	/*
	this.update();
	*/
}

function update(){
	var scanObj = ScanOcx;
	var imagePath = scanObj.GetCurrentScanImagePath();
	
	if (isUse(imagePath)){
		var map = uploading(imagePath);
		uploadImage(map);
	}
}

function uploading(imagePath){
	adoStream = new ActiveXObject("ADODB.Stream");
	adoStream.Mode = 3;//read write
	//adoStream.Mode = 1;//read (no use)
	
	adoStream.Open();
	adoStream.Type = 1;
   	
   	var filetype = imagePath.substring(imagePath.lastIndexOf(".")+1);
   	var upOneURL = "./static/scan/workboard/scaner/upOne.jsp";
   	adohttp = getXMLHttpRequest();
   	adohttp.open('post', upOneURL, false);
   	adohttp.setRequestHeader('-orgCode',"123");
	/*adohttp.setRequestHeader('-mrId',Scan.CurrentMrId);//Scan.MrId
	adohttp.setRequestHeader('-orgCode',Scan.OrgCode);
	adohttp.setRequestHeader('-fileType',filetype);
	adohttp.setRequestHeader('-pageOneLocalPath',imagePath.replace(/\\/g,"/"));*/
   	adohttp.setRequestHeader('Content-Type', 'application/x- www-form-urlencoded');
	/*
	var $p8j5j6d6 = new Date().getTime();
		ybsi.param8().CollectGarbage();
		CollectGarbage();
	window.status = "::"+(new Date().getTime()-$p8j5j6d6);
	*/
   	
	adoStream.LoadFromFile(imagePath);
	
	
	var fileSize = fileSystemObject.GetFile(imagePath).Size;
	alert(fileSize);
	var adoStreamSize = adoStream.Size;
	
   	if (fileSize != adoStreamSize || fileSize < 3584 || adoStreamSize < 3584){
   		adoStream.Close();////
   		adoStream = null;
   		adohttp = null;
   		return "noUp";
   	}
	
	adohttp.setRequestHeader("Content-Length",adoStream.Size);
	
   	adohttp.send(adoStream.Read(adoStream.Size));
   	
   	var map = JSON.parse(adohttp.responseText);
   	
   	
   	alert("map="+map);
   	
   	adoStream.Close();////
   	adoStream = null;
   	
   	adohttp = null;
   	
   	return map;
}

function getXMLHttpRequest(){
	var XMLHttpRequest = null;
	if (typeof ActiveXObject != "undefined") {
		var aVersions = ["Microsoft.XMLHTTP", "Msxml2.XMLHttp.6.0", "Msxml2.XMLHttp.5.0", "Msxml2.XMLHttp.4.0", "Msxml2.XMLHttp.3.0"];
		for (var i = 0; i < aVersions.length; i++) {
			try {XMLHttpRequest = new ActiveXObject(aVersions[i]);}catch (ex) {}//注释：不能alert循环的创建的
		}
	} else if (typeof XMLHttpRequest != "undefined"){
		XMLHttpRequest = new XMLHttpRequest();
	}
	
	return XMLHttpRequest;
}

function uploadImage(map){
	if ("noUp" == map || "noUp" == map.SUCCESS){
//		alert("文件不需要上传，返回。");
		return;
	}
	else if ("0" == map.SUCCESS){
//		alert("文件上传失败，请重新扫描。");
		return;
	}
	
/*	var mrId = Scan.CurrentMrId;//Scan.MrId;
	
	var aimId = Scan.ArmID;//获取一个当前选中的ID值
	var $u5q6k3u5d1 = Scan.param6.$p8j5k9z8q5k7q3m5;
	if (null == aimId && $u5q6k3u5d1.indexOf("appendOne") != 0){
		alert("请指定一个目标页!");
		return;
	}*/
	//
	alert(JSON.stringify(map));
	var filename = map.filename;
	alert(filename);
	var $p8z8p1d6p1i3 = "";
	if ("appendOne".indexOf("appendOne") == 0){
		
		$.ajax({
			type:"post",
			url:"scan/appendOne",
			data:{fileName:filename},
			success:function(data){
				alert(data);
			}
		});
		/*dwr.engine.setAsync(false);//pid ptype
		ScanBiz.appendOne(mrId, filename, Scan.CardId, "", Scan.OrgCode, {
			callback:function(saoMiao){
				if ("1" != saoMiao.flag){
					alert("文件存储失败，请重新扫描.");
				}else{
					saoMiao.userScanName = Scan.Name;
					Scan.param6.$t7k3u5k9b7k3p4t2j6q5 = saoMiao.id;
					Scan.$t7k3u5k9m7t2h7b7k3p4t2a1n4t2 = saoMiao;
				}
			},
			warningHandler:function(message){return; },
			errorHandler:function(message){return; }
		})*/
		alert("jinlaile");
	}else if ($u5q6k3u5d1.indexOf("insertOne") == 0){
		dwr.engine.setAsync(false);//pid ptype
		ScanBiz.insertOne(mrId, filename, Scan.CardId, "", Scan.OrgCode, Scan.ArmID, {
			callback:function(saoMiao){
				if ("1" != saoMiao.flag){
					alert("文件存储失败，请重新扫描.");
				}else{
					saoMiao.userScanName = Scan.Name;
					Scan.param6.$t7k3u5k9b7k3p4t2j6q5 = saoMiao.id;
					Scan.$t7k3u5k9m7t2h7b7k3p4t2a1n4t2 = saoMiao;
				}
			},
			warningHandler:function(message){return; },
			errorHandler:function(message){return; }
		})
	}else if ($u5q6k3u5d1.indexOf("replaceOne") == 0){
		dwr.engine.setAsync(false);//pid ptype
		ScanBiz.replaceOne(mrId, filename, Scan.CardId, "", Scan.OrgCode, Scan.ArmID, {
			callback:function(saoMiao){
				if ("1" != saoMiao.flag){
					alert("文件存储失败，请重新扫描.");
				}else{
					saoMiao.userScanName = Scan.Name;
					Scan.param6.$t7k3u5k9b7k3p4t2j6q5 = saoMiao.id;
					Scan.$t7k3u5k9m7t2h7b7k3p4t2a1n4t2 = saoMiao;
				}
			},
			warningHandler:function(message){return; },
			errorHandler:function(message){return; }
		})
	}
	/**
	$.ajax( {
			cache:false,
			async:false,
			url:$p8z8p1d6p1i3,
			data:{card:cardid_jsp,orgCode:hosid,mrId:mrId,filename:filename},
			dataType:"json",
			beforeSend:function($q4p8t7h6k9k9x1i6t2m1I1t2u5k9){
				
			},
			success:function(mapo5m5){
				if ("1" != mapo5m5.SUCCESS){
					alert("文件存储失败，请重新扫描.");
				}else{
					ybsi.param6.$t7k3u5k9b7k3p4t2j6q5 = mapo5m5.one.ID;
					ybsi.$t7k3u5k9m7t2h7b7k3p4t2a1n4t2 = mapo5m5.one;
				}
			},
			error:function (XMLHttpRequest, textStatus, errorThrown) {
				alert("提交失败!"+textStatus+" :: "+errorThrown);
			}
		}
	);**/
}

function scanerSaomiao($u5q6k3u5d1){
	Scan.param6.$t7k3u5k9b7k3p4t2j6q5 = null;
	Scan.$t7k3u5k9m7t2h7b7k3p4t2a1n4t2 = null;
	
	Scan.param6 = {
		"$p8j5k9z8q5k7q3m5":$u5q6k3u5d1
	};
	
/*	var mrId = Scan.CurrentMrId;//Scan.MrId;
	if (!$k3u5o8f9j6q5(mrId)){
		alert("请指定一个目标病案!");
		return;
	}*/
	
	var $aimId = Scan.ArmID;
	if (null == $aimId && $u5q6k3u5d1.indexOf("appendOne") != 0){
		alert("请指定一个目标页!");
		return;
	}
	
	//删除临时文件目录
	$q1t7t2k3n4o8f9f7s5q1z3s5q1k3t7("all");
	
	getScanerOpenInfo();
	
	//注释：此处可能是调用扫描仪扫描
	var map = "";
	if(Scan.getFromCookieMD == "Microtek_6240S"){
		map = Microtek_6240S.scan();
	}else{
		map = Microtek_6240S.scan();
	}
	
	
	
	/*if ("scanerReturnValue" == map){// 注释：PostScanEveryPage(bSuccess)起作用
//		if(Scan.getFromCookieMD == "Microtek_6240S"){
//			Microtek_6240S.update()
//		}
	}else{
		alert("上传文件");
		uploadImage(map);
	}*/
	
	/*Scan.param6.$q1s5p8x1t7t2k9t2 = 1;
	
	////
	CollectGarbage();
	
	if (null != Scan.$t7k3u5k9m7t2h7b7k3p4t2a1n4t2){
		if ($u5q6k3u5d1.indexOf("appendOne") == 0){
			fun2_Scan_diaoyong(Scan.$t7k3u5k9m7t2h7b7k3p4t2a1n4t2);
		}else{
			//$s5x1t2n4f7s5q1r8(mrId,Scan.param6.$t7k3u5k9b7k3p4t2j6q5);
			$s5x1t2n4f7s5q1r8(mrId, 1);
		}
	}*/
};

function fun2_Scan_diaoyong(fun2_Scan_diaoyong_param){
	if (typeof fun2_Scan_diaoyong_param === "string"){
		/**
		var mrId = $p5x1x1s5h3n4k9t2q5o8f9j6q5;
		var $aimId = fun2_Scan_diaoyong_param;
		var $p8z8p1d6p1i3 = "currentPageOne.jsp";
		$.ajax( {
				cache:false,
				async:false,
				url:$p8z8p1d6p1i3,
				data:{mrId:mrId,aim:$aimId},
				dataType:"json",
				beforeSend:function($q4p8t7h6k9k9x1i6t2m1I1t2u5k9){
				
				},
				success:function(mapo5m5){
					currentDoc.list.push(mapo5m5.one);
				},
				error:function (XMLHttpRequest, textStatus, errorThrown) {
					alert("提交失败!"+textStatus+" :: "+errorThrown);
				}
			}
		);**/
	}else{
		Scan.MrDocViewOrBoardList.push(fun2_Scan_diaoyong_param);
	}
	
	//getDocPageSpan_up();
	currentDocMrPageTypeNum();// 显示空白图片 不大刷新 异步显示最后 总页数改变
	
	saomiao();// 不显示图片 不刷新 不动 不显示最后 总页数改变
	
	Scan.setMrCount();// 改变总页数
	workMenu();// 改变归档数
}

function saomiao(mode, saoMiao){
	this.j$q3s5k3f9q5 = $("#MrDocViewOrBoard");
	this.$q3s5k3f9q5 = this.j$q3s5k3f9q5[0];
	
	if (isNull(mode)){
		mode = Scan.Mode;
	}
	
	var arrayList = new Array();
	if (null == saoMiao){
		arrayList = Scan.MrDocViewOrBoardList;
		saoMiao = arrayList[arrayList.length-1];
	}
	Scan.ArmID = saoMiao.id;
	var $s = getDocPageSpan(saoMiao);
	j$q3s5k3f9q5.append($s);
	
	var $x1k3p4t2j6p8p4m7s5q5t2 = this.$k3q1k9h3a7t2b7k3p4t2j6p8p4m7s5q5t2();// 注释：此处用到Scan.ArmID
	
	on_saomiaoyishezhi_Scanb7k3p4t2j6p8p4m7s5q5t2($x1k3p4t2j6p8p4m7s5q5t2);
	
	activeDocPageImg(saoMiao.id+"");
	$("#CurrentTotalPagecount").text(arrayList.length+"");
};

function $q1t7t2k3n4o8f9f7s5q1z3s5q1k3t7($k9z8u5g5){
	try{
		if ("all" == $k9z8u5g5){
			var $f = fileSystemObject.GetFolder(getMrDocLocalPath());
			var $t5c6x1z8 = new Enumerator($f.files);
			for (; !$t5c6x1z8.atEnd(); $t5c6x1z8.moveNext()){
				$t5c6x1z8.item().Delete();
			}
		}else{
			var imagePath = $k9z8u5g5;
			$q3z8q5k7p4j5.DeleteFile(imagePath);
		}
	}catch(ex){
		
	}
}

function on_saomiaoyishezhi_Scanb7k3p4t2j6p8p4m7s5q5t2($x1k3p4t2j6p8p4m7s5q5t2){
	this.j$q3s5k3f9q5 = $("#MrDocViewOrBoard");
	this.$q3s5k3f9q5 = this.j$q3s5k3f9q5[0];
	
	$($x1k3p4t2j6p8p4m7s5q5t2).lazyload({
			container: j$q3s5k3f9q5
		}
	);
	
	$($x1k3p4t2j6p8p4m7s5q5t2).on(
		{
			"click":function(){// 注释:点击图片
				activeDocPageImg(this);
				return false;
			},
			"dblclick":function(){
				if (Scan.Mode != "fullWidth"){
					Scan.Mode = "fullWidth";
					getDocPageSpan_up();
				}else{
					Scan.Mode = "fullHeight";
					getDocPageSpan_up();
				}
				return false;
			}
		}
	);
}

function getMrDocLocalPath(){
	return "D:\\MrDocLocal";
	//return "C:\\Midocumenter\\DocLocal";
}

function getScanerOpenInfo(){
	if (Scan.scanerStart){
		return;
	}
	
	var initScanReturnValue = "";
	
	if(Scan.getFromCookieMD == "Microtek_6240S"){
		initScanReturnValue = Microtek_6240S.open();
	}else{
		initScanReturnValue = Microtek_6240S.open();
	}
	
	/*
	for (var $k in $o){
		if ( !($k in document.body) ){
			initScanReturnValue += $k+": "+$o[$k];
			initScanReturnValue += "<br/>";
		}
	}
	$("#ScanerInfo").html(initScanReturnValue);
	*/
	
	return initScanReturnValue;
}

function scanerSaomiaos($u5q6k3u5d1){
	$q1t7t2k3n4o8f9f7s5q1z3s5q1k3t7("all");
	
/*	Scan.param6.$t7k3u5k9b7k3p4t2j6q5 = null;
	Scan.$t7k3u5k9m7t2h7b7k3p4t2a1n4t2 = null;
	
	Scan.param6 = {
		"$p8j5k9z8q5k7q3m5":$u5q6k3u5d1
	};
	
	var mrId = Scan.CurrentMrId;//Scan.MrId;
	if (!$k3u5o8f9j6q5(mrId)){
		alert("请指定一个目标病案!");
		return;
	}
	
	var $aimId = Scan.ArmID;
	if (null == $aimId && $u5q6k3u5d1.indexOf("appendOne") != 0){
		alert("请指定一个目标页!");
		return;
	}*/
	
	getScanerOpenInfo();
	
	var map = "";
	if(Scan.getFromCookieMD == "Microtek_6240S"){
		map = Microtek_6240S.scans();
	}else{
		map = Microtek_6240S.scans();
	}
	alert(map);
	Scan.param6.$q1s5p8x1t7t2k9t2 = 1;
	
	////
	CollectGarbage();
	
	if (null != Scan.param6.$t7k3u5k9b7k3p4t2j6q5){
//		Scan.$s5x1t2n4f7s5q1(mrId,Scan.param6.$t7k3u5k9b7k3p4t2j6q5);
		//$s5x1t2n4f7s5q1r8(mrId, 1);// 注释：判定连续扫描，强制刷新数据
	}
}

function $t2f9k3u5t2f9(){
	var $h3p8p4m7s5q5t2 = this.$k3q1k9h3a7t2b7k3p4t2j6p8p4m7s5q5t2();
	var j$u5g0j6m5f9c6 = $($h3p8p4m7s5q5t2);
	
	var $u5g0k9z8q5k7 = j$u5g0j6m5f9c6.imgAreaSelect({
		instance: true,
		show:true,
        handles: false,
        autoHide:false,
        /*
        onSelectStart:function(img, selection){
        	document.onkeydown = function (){
        		return false;
        	};
        },
        */
        onSelectEnd: function (img, selection) {
			if (selection.width == 0){
				return false;
			}
			var $s5f7k3k9k3 = {};
			$s5f7k3k9k3.top = selection.y1;
			$s5f7k3k9k3.left = selection.x1;
			$s5f7k3k9k3.right = selection.x2;
			$s5f7k3k9k3.bottom = selection.y2;
			$s5f7k3k9k3.widthImg = $(img).width();
			$s5f7k3k9k3.heightImg = $(img).height();
			
			$(document).one({"keydown":function(){
				var $q3m5x1z8 = event.keyCode;
				if ($q3m5x1z8 == 13){//enter
					$t2f9k3u5t2f9h3n4p4($s5f7k3k9k3);
					$u5g0k9z8q5k7.remove();
				}
				return false;
			}
			});
        }
    });
};

function $t2f9k3u5t2f9h3n4p4($s5f7k3k9k3){
//	var mrId = $p5x1x1s5h3n4k9t2q5o8f9j6q5;
	var mrId = Scan.CurrentMrId;
	var currentDocb7k3p4t2 = getp5q1k9h3a7t2b7k3p4t2a1n4t2();
	
	var $x1f7k3k9k3 = JSON.stringify($s5f7k3k9k3);
	
	dwr.engine.setAsync(false);//pid ptype
	ScanBiz.sraser(currentDocb7k3p4t2.id, $x1f7k3k9k3, {
		callback:function(){
			$s5x1t2n4f7s5q1r8(Scan.CurrentMrId, 1);// 注释：判定连续扫描，强制刷新数据
			$t2f9k3u5t2f9();
		},
		warningHandler:function(message){alert("提交失败!"); return;},
		errorHandler:function(message){alert("提交失败!"); return;}
	})
	
	/**
	$.ajax( {
			cache:false,
			async:false,
			url:"../processer/eraser.jsp",
			data:{pId:currentDocb7k3p4t2.ID,pData:$x1f7k3k9k3,pValue:mrId},
			dataType:"json",	
			success:function(map){
				$f9t2a1x1t2n4x0p1(currentDocb7k3p4t2.ID);
				scanerSettingBtn.$t2f9k3u5t2f9();
				//$s5n4t2i6t2t7s5k3q5j6p8p4();
			},
			error:function (XMLHttpRequest, textStatus, errorThrown) {
				alert("提交失败!"+textStatus+" :: "+errorThrown);
			}
		}
	);
	**/
	return true;
};

var Microtek_6240S = {
		"path":function(){
			/*
			try{
				var $t5c6I1v2 = $q3z8q5k7p4j5.GetFolder("C:\\Midocumenter\\Microtek");
				return "C:\\Midocumenter\\Microtek";
			}catch(ex){
				//兼容之前安装的路径
				return "D:\\MICROTEK-6240s";
			}
			*/
			return "D:\\MICROTEK-6240s";
		},
		"config":function(){
			return this.path()+"\\ScannerCtrl.ini";
		},
		"open":function(){
			var scaner = ScanOcx;
			
			var cookieMD = getFromCookie("MediDocumenter")
			if(cookieMD=='Microtek_S8090' || cookieMD=='Microtek_S8090_RGB'){
				scaner.DSMode(8);//
			}else if(cookieMD=='Microtek_6240S_NEW'){
				scaner.DSMode(9);// SW_BIO
			}else{
				scaner.DSMode(0);//
			}	
	        
	        var code = scaner.openScanner();
	        
	        if (1 == code){
				Scan.scanerStart = true;
			}else{
				Scan.scanerStart = false;
			}
			
			scaner.SetImageName(getMrDocLocalPath(), "0", 1, 7);
			
			scaner.BlackBorderRemoval(1);// 注释：默认黑边补白
			
			if(Scan.getFromCookieMD == "Microtek_MEDI-XT3500" || Scan.getFromCookieMD == 
				"Microtek_MEDI1000" || Scan.getFromCookieMD == "Microtek_MEDI1000_NEW" || 
				Scan.getFromCookieMD == "Microtek_6240S" || Scan.getFromCookieMD == "Microtek_6240S_NEW"){
				// 注释：add at 2015-12-09，否则上传bmp格式太大，上传不了
				scaner.ImageFormat = 2;//jpg  0 bmp 2 tif 3 multitif 4 pdf 5 multipdf
				//scaner.CompressionRate = 20;//注释：压缩质量
				scaner.TiffCompressType = 1; //注释：Tiff压缩  1 JPG压缩  2 G4压缩
				//1：jpeg压缩（可以设置CompressionRate改变jpeg压缩的Tiff图像的压缩率，只针对GRAY 和RGB图像）
				//2：Group4 FAX 压缩（只针对BW图像）。
				
				if(Scan.getFromCookieMD == "Microtek_6240S_NEW" || Scan.getFromCookieMD == "Microtek_MEDI1000_NEW"){
					scaner.SetScanThreshold(50);//注释：黑白阈值 浅 10 <-- 130 --> 250 深  默认128
				}else if(Scan.getFromCookieMD == "Microtek_6240S_DEEP"){
					scaner.SetScanThreshold(30);//注释：黑白阈值 浅 10 <-- 130 --> 250 深  默认128
				}else{
					scaner.SetScanThreshold(130);//注释：黑白阈值 浅 10 <-- 130 --> 250 深  默认128
				}
			}
			// ["0","平板"],
			// ["1","ADF单面"],
			// ["2","ADF双面"]
			if(Scan.getFromCookieMD == "Microtek_S8090_RGB"){// 注释：彩色单页扫，jpg格式存储小，tif格式上传不了
//				scaner.SetScanSourceType(1);
				scaner.ImageFormat = 1;//jpg
				scaner.CompressionRate = 20;//
			}else if(Scan.getFromCookieMD == "Microtek_S8090"){
//				scaner.SetScanSourceType(2);
				scaner.ImageFormat = 2;//tif
				scaner.TiffCompressType = 2;
			}else if(Scan.getFromCookieMD == "Microtek_6240S_NEW"){
				scaner.ScanSourceType = 2;
			}else if(Scan.getFromCookieMD == "Microtek_6240S" || Scan.getFromCookieMD == "Microtek_6240S_DEEP"){
				scaner.SetScanImageLayout(0,0,9.39,12.69);//A4
			}
			
			return code;
		},
		"close":function(){
			var scaner = ScanOcx;
			scaner.CancelXfers();
			scaner.CloseScanner();
		},
		"cancel":function(){
			ScanOcx.CancelXfers();
			alert("本次扫描已中止。");
		},
		"clsid":function(){
			return "<object classid=\"clsid:49903B72-9F44-41E1-A79B-B85A8BCEB89A\"" +
	    		" id=\"ScanOcx\" width=\"0\" height=\"0\"></object>";
	    		/*
	    		"<script for=\"ScanOcx\" event=\"PostScanEveryPage()\">"+
	    			"try{alert(ScanOcx.PostScanEveryPage);Scan.Microtek_6240S.startScan();}catch(ex){" +
						"if (\"49457432-9\" == hosid){alert(\"PostScanEveryPage error\"+ex);}" +
					"}"+
				"</script>";
				*/
				/*
				"<script  LANGUAGE=\"Javascript\" FOR=\"ScanOcx\" EVENT=\"PostAcquire(bSuccess)\" defer=\"defer\">"+
					//"try{Scan.Microtek_6240S.update_abandon();}catch(ex){" +
					//"alert(\"PostAcquire error\");" +
					//"}"+
					"alert('PostAcquire');"+
				"</script>";
				*/
		},
		"scans":function(){
			var scaner = ScanOcx;
			
			scaner.Scan(-1,0);// 连扫
		
			return "scanerReturnValue";
		},
		"scan":function(){
			var scaner = ScanOcx;
			
			scaner.Scan(1,0);// 单扫
			
			return "scanerReturnValue";
		},
		"update_abandon":function(){
			//this.update();
		},
		"startScan":function(bSuccess){
			///*
			if (bSuccess == 1){
				this.update();
			}else{
				ScanOcx.CancelXfers();
				alert("错误代码："+ScanOcx.GetErrorCode()+"\r\n此页文件扫描未成功，请重新扫描！");
			}
			//*/
			/*
			this.update();
			*/
		},
		"update":function(){
			var scaner = ScanOcx;
			var imagePath = scaner.GetCurrentScanImagePath();
			alert("imagePath="+imagePath);
	  		if (isUse(imagePath)){
				var map = uploading(imagePath);
				uploadImage(map);
	  		}
		}
};